home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / html / Window.js < prev   
Encoding:
Text File  |  2007-04-11  |  14.9 KB  |  477 lines

  1. /****i* SOURCE_FILE/INFO
  2.   *
  3.   * NAME
  4.   *  Window.js
  5.   *
  6.   * USAGE
  7.   *  Part of Netobjects JavaScript Library.
  8.   *
  9.   * COPYRIGHT
  10.   *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.   *  All Rights Reserved.
  12.   *
  13.   *  This is an unpublished work protected by Website Pros, Inc.
  14.   *  as a trade secret, and is not to be used or disclosed except as
  15.   *  expressly provided in a written license agreement executed by
  16.   *  you and Website Pros, Inc.
  17.   *
  18.   *      <copyright@websitepros.com>
  19.   *
  20.   * NOTES
  21.   *  JavaScript code.
  22.   *
  23.   *****/
  24.  
  25. if (!IS_isModuleInitialized("IS.NOF.HTML.Window"))
  26. {
  27.   
  28.   /****h* NOF_JavaScript_Library/NOF.HTML.Window
  29.     *
  30.     * NAME
  31.     *  NOF.HTML.Window
  32.     *
  33.     * DESCRIPTION
  34.     * External dependencies: NOF.WindowEvent, NOF.HTML.Document  
  35.     ****/
  36.   
  37.   /**
  38.     * constructor   
  39.     *  @param _doc
  40.     *  @param _name
  41.     **/ 
  42.   function NOF_HTML_Window( _doc, _name ) {
  43.     this.__proto__          = NOF_HTML_Window.prototype;
  44.     
  45.     if (arguments.length > 0){
  46.       this.name               = _name;
  47.       this.children           = new Array();
  48.       this.listeners          = new Array();  
  49.       
  50.       if ( _doc != null){
  51.         if (typeof(_doc.getRawDoc) == 'function')
  52.           this.doc = _doc;
  53.         else
  54.           this.doc = new NOF.HTML.Document(_doc);
  55.       }else{
  56.           this.doc = null;
  57.       }
  58.       this.document = this.doc;  //this temporarily to fix all the editors  
  59.     }
  60.   }
  61.   {
  62.     var member = NOF_HTML_Window.prototype;
  63.     
  64.     //default values for members
  65.     member.name               = null;
  66.     member.defaultName        = "GENERIC_WINDOW";
  67.     member.visible            = false;
  68.     member.initialised        = false;
  69.     member.closed             = false;  
  70.     
  71.     //TODO: change it to app for consistency. would require updating all the editors
  72.     member.appHnd             = null;  //this really should have been just app but some existing editor classes alreay make use of it for a different
  73.     member.parent             = null;  
  74.     member.children           = null;
  75.     member.listeners          = null;  
  76.     
  77.     member.doc                = null;           
  78.     member.document           = null;  //this temporarily to fix all the editors   
  79.     
  80.     member.defaultResource    = null;
  81.     
  82.     member.width              = null;
  83.     member.height             = null;
  84.     
  85.     var method = NOF_HTML_Window.prototype;
  86.     //member accessors
  87.     method.getDoc = function (){ return this.doc; };
  88.     method.setDoc = function ( doc ){ this.doc = doc; };
  89.     
  90.     method.getName = function () {
  91.         if (this.name != null) {
  92.             return this.name;
  93.         } else {
  94.             return this.defaultName; 
  95.         }
  96.     }
  97.     method.setName = function ( name ){ this.name = name; }
  98.     
  99.     method.getApp = function (){ return this.appHnd; };
  100.     method.setApp = function (app){ this.appHnd = app; };
  101.     
  102.     method.getResourceProperty = function ( key ){ 
  103.       return this.getApp().getResourceProperty( key ); 
  104.     };  
  105.     
  106.     method.getParent = function (){ return this.parent; };
  107.     method.setParent = function (parent){
  108.       this.parent = parent;
  109.       this.appHnd = parent.getApp();
  110.       this.addListener( parent );
  111.     };
  112.     
  113.     method.init = function (){ 
  114.       this.onInit( new NOF.WindowEvent( NOF.WindowEvent.WINDOW_INITIALISED, this ) );
  115.     };  
  116.     method.isInitialised = function (){ return this.initialised; };
  117.     method.onInit = function ( evt ){//default onInit handler simply notifies listeners of the initialization
  118.       if (! this.isInitialised () ){
  119.         for (var i = 0; i < this.listeners.length; i++ ){
  120.           try{
  121.             this.listeners[i].windowInitialised( event );
  122.           }catch(e){
  123.           }
  124.         }
  125.         this.initialised = true;
  126.       }    
  127.     };        
  128.     method.super_onInit       = method.onInit; //merely a convenience method for subclasses to invoke it when overriding it  
  129.     
  130.     method.close = function (){
  131.       this.onClose( new NOF.WindowEvent( NOF.WindowEvent.WINDOW_CLOSED, this ) );
  132.     }
  133.     
  134.     method.onClose = function ( event ){
  135.       if (! this.isClosed() ){
  136.         for (var i = 0; i < this.listeners.length; i++ ){
  137.           try{          
  138.             this.listeners[i].windowClosed( event );
  139.           }catch(e){
  140.           }
  141.         }
  142.         this.closed = true;
  143.       }    
  144.     }
  145.     
  146.     method.windowClosed = function (event) {
  147.       if (event.getID() == NOF.WindowEvent.DIALOG_CLOSED)
  148.         this.removeChild( event.getSource() );
  149.     }
  150.     
  151.     method.super_onClose      = method.onClose;//merely a convenience method for subclasses to invoke it when overriding it  
  152.     method.isClosed = function (){ return this.closed; };
  153.     
  154.     method.onDialogCancel = function () {}
  155.     method.onDialogOk = function () {}
  156.  
  157.     method.getChildren = function (){ return this.children; };
  158.     method.setChildren = function (children){ this.children = children; };
  159.     
  160.     method.getListeners = function (){ return this.listeners; };
  161.     method.setListeners = function (listeners){ this.listeners = listeners; };
  162.     
  163.     method.show = function ( dlgName){ 
  164.       var contentId = (dlgName != null ? dlgName : this.getName() );
  165.       
  166.       if ( contentId != null)
  167.         this.document.setElementAttribute (contentId, "class", "tabshow");
  168.     }; 
  169.     
  170.     method.hide = function ( dlgName ){
  171.       var contentId = (dlgName != null ? dlgName : this.getName() );
  172.       
  173.       if ( contentId != null)
  174.         this.document.setElementAttribute (contentId, "class", "tabhide");
  175.     };
  176.     
  177.     method.getChild = function ( _name ){ 
  178.       for (var i = 0;  i < this.children.length; i++ )
  179.         if ( this.children[i].getName() == _name )
  180.           return this.children[i];
  181.       return null;
  182.     };  
  183.     
  184.     method.addChild = function ( child ){
  185.       for (var i=0; i<this.children.length; i++)
  186.         if ( child == this.children[i] ) 
  187.           return;
  188.       
  189.       this.children[this.children.length] = child;
  190.       child.setParent( this );
  191.     };
  192.     
  193.     method.removeChild = function ( child ){
  194.       for (var i = 0; i < this.children.length; i++ )
  195.         if (child == this.children[i] ){
  196.           this.children[i] = this.children[this.children.length-1];
  197.           this.children.length--;
  198.         }
  199.     };  
  200.     
  201.     method.addListener = function ( listener ){
  202.       for (var i=0; i<this.listeners.length; i++)
  203.         if ( this.listeners[i] == listener ) 
  204.           return;
  205.       
  206.       this.listeners[this.listeners.length] = listener;
  207.     };  
  208.     
  209.     method.removeListener = function ( listener ){
  210.       for (var i = 0; i < this.listeners.length; i++ )
  211.         if ( this.listeners[i] == listener ) {
  212.           this.listeners[i] = this.listeners[this.listeners.length -1];
  213.           this.listeners.length--;
  214.         }
  215.     };  
  216.     
  217.     method.notifyListeners = function ( event ){
  218.       for (var i = 0; i < this.listeners.length; i++ ){
  219.         try{        
  220.           this.listeners[i].actionPerformed( event );
  221.         }catch(e){
  222.           this.appHnd.ERROR('exc: ' + e.message);        
  223.         }
  224.       }
  225.     };  
  226.     
  227.     /** action
  228.     
  229.         @param evt name.
  230.     */
  231.     method.action = function ( evt ) {
  232.       var action = evt.getID();
  233.       
  234.       var tmpStr      = this.getName() + ".";
  235.       var isQualified = false;
  236.       
  237.       if ( (isQualified = action.indexOf( tmpStr ) == 0) || (action.indexOf(".") == -1)) {//current window is the target
  238.         if ( isQualified )
  239.           action = action.substring( tmpStr.length );
  240.   
  241.         try {
  242.           return eval("this.on" + action + "( evt.getSource() )");
  243.         }catch( e ){          
  244.           //debugger;
  245.           //this.appHnd.ERROR( "[" + this.getName() + "] " + action +  " failed! " + e.name + ": " + e.message );
  246.           //throw e;
  247.         }
  248.       }else{//iterate over the list of children and if one matches invoke action on it
  249.         var target = action.substring( 0, action.indexOf(".") );
  250.         
  251.         //strip the window name from event.id. this way we allow propagation down to window hierarchy
  252.         evt.setID( action.substring( target.length + 1 ) );
  253.         for (var i=0; i < this.children.length; i++) {
  254.           if ( target == this.children[i].getName() ) {
  255.             return this.children[i].action( evt );          
  256.           }
  257.         }
  258.       }
  259.     } 
  260.     
  261.     /** actionPerformed
  262.         @param evt name.
  263.     */
  264.     method.actionPerformed = function ( evt ) {    
  265.       //this.appHnd.TRACE( "[action performed] " + this.getName() + " - " + evt.getID() + " - " + evt.getSource());
  266.       return this.action(evt);
  267.     }
  268.     
  269.     method.toString = function () {
  270.       return this.getName() + "{ Parent:" + this.parent + ";ChildrenNr:" + this.children.length + ";Listeners:" + this.listeners.length + "}";  
  271.     }
  272.     
  273.     method.setTitle = function ( title ){
  274.       this.getApp().getFSIApp2().SetDialogTitle( title );
  275.     }
  276.     
  277.     method.setSize = function ( width, height){
  278.       var app2 = this.getApp().getFSIApp2();    
  279.       var x1 = width * app2.LogPixelsX / 96;
  280.       var y1 = height * app2.LogPixelsY / 96;
  281.       
  282.       var browserDoc = this.getDoc().getRawDoc();
  283.       var windowHnd     = this.getWindowHandle();
  284.       
  285.       if (x1 != browserDoc.body.clientWidth || y1 != browserDoc.body.clientHeight){
  286.         var h = windowHnd.dialogHeight;
  287.         h = h.substr(0, h.length - 2) - 0;
  288.         var w = windowHnd.dialogWidth;
  289.         w = w.substr(0, w.length - 2) - 0;
  290.         
  291.         windowHnd.dialogWidth  = w + x1 - browserDoc.body.clientWidth + 'px';
  292.         windowHnd.dialogHeight = h + y1 - browserDoc.body.clientHeight + 'px';
  293.       }    
  294.     }
  295.     
  296.     method.getPreferredWidth = function ( ){
  297.       return this.width;
  298.     }
  299.     
  300.     method.setPreferredWidth = function ( width ){
  301.       this.width  = width;
  302.     }
  303.   
  304.     method.getPreferredHeight = function ( ){
  305.       return this.height;
  306.     }
  307.     
  308.     method.setPreferredHeight = function ( height ){
  309.       this.height = height;
  310.     }
  311.     
  312.     method.getWindowHandle = function (){
  313.       return this.doc.getRawDoc().parentWindow;  
  314.     }
  315.     
  316.     method.release = function (){
  317.       if (this.children && typeof this.children.length) {
  318.         for (var i=0; i < this.children.length; i++)
  319.           this.children[i].release();
  320.       }  
  321.       this.parent     = null;
  322.       this.appHnd     = null;
  323.       this.children   = null;
  324.       this.listeners  = null;  
  325.     
  326.       this.doc        = null;           
  327.       this.document   = null;
  328.     
  329.       this.defaultResource = null;
  330.     }
  331.     
  332.     method.super_release = method.release;  
  333.   }
  334.   HTML.__proto__.Window = NOF_HTML_Window;
  335.   // keep for compatibility with older versions
  336.   //NOF.__proto__.HtmlWindow  = NOF_HTML_Window;
  337.   
  338.   /**
  339.     NOF.TabbedMenuWindow class. Base class for windows with a tabbed menu.
  340.     
  341.     Constructor 
  342.     
  343.     @param _doc
  344.     @param _name
  345.   */
  346.   function NOF_TabbedMenuWindow(_doc, _name){
  347.     this.__proto__  = NOF_TabbedMenuWindow.prototype;  
  348.     
  349.     if (arguments.length == 0){ //default constructor call
  350.       this.SUPER();
  351.     }else{
  352.       this.SUPER( _doc, _name );      
  353.     }
  354.   } 
  355.   
  356.   NOF_TabbedMenuWindow.inherits (HTML.Window)
  357.   {
  358.     var member = NOF_TabbedMenuWindow.prototype;
  359.     member.tabbedMenu = null;  
  360.   
  361.     var method = NOF_TabbedMenuWindow.prototype;  
  362.     method.getMenu          = function (){ return this.tabbedMenu;};
  363.     method.setMenu          = function ( menu ){ this.tabbedMenu = menu; };  
  364.     
  365.     method.release = function (){
  366.       this.super_release();
  367.       this.tabbedMenu.release();
  368.       this.tabbedMenu  = null;
  369.     }
  370.     method.onMenuHeaderDraw = function (){
  371.       this.document.write ( this.getMenu().getHeader() );
  372.     }
  373.     
  374.     method.onMenuFooterDraw = function (){
  375.       this.document.write ( this.getMenu().getFooter() );
  376.     }  
  377.     
  378.     /**
  379.     @param event NOF.MenuEvent
  380.     */
  381.     method.menuSelected     =   function ( event ){
  382.       var child = this.getChild( event.getSource().getId() );
  383.       if (child != null)
  384.         child.show(); //menu item has to be constructed w/ id = window name
  385.     }
  386.     
  387.     method.menuDeselected   = function ( event ){
  388.       var child = this.getChild( event.getSource().getId() );
  389.       if (child != null)
  390.         child.hide(); //menu item has to be constructed w/ id = window name
  391.     }  
  392.   } 
  393.   
  394.   //NOF.__proto__.TabbedMenuWindow  = NOF_TabbedMenuWindow;  
  395.   HTML.__proto__.TabbedMenuWindow  = NOF_TabbedMenuWindow;
  396.     
  397.   /**
  398.     NOF.HTML.EditorWindow class. Base class for editor windows.
  399.     
  400.     Constructor 
  401.     
  402.     @param _editedElem Object
  403.     @param _doc
  404.     @param _name
  405.   */
  406.   function NOF_EditorWindow(_editedElement, _doc, _name){
  407.     this.__proto__  = NOF_EditorWindow.prototype;
  408.     
  409.     if (arguments.length == 0){ //default constructor call
  410.       this.SUPER();    
  411.     }else{
  412.       this.SUPER( _doc, _name );
  413.       this.editedElement = _editedElement;    
  414.     }
  415.   }
  416.   
  417.   NOF_EditorWindow.inherits( HTML.Window )
  418.   {
  419.     var member = NOF_EditorWindow.prototype;  
  420.     member.editedElement = null;    
  421.     
  422.     var method = NOF_EditorWindow.prototype;  
  423.     method.getEditedElement    = function (){ return this.editedElement; };
  424.     method.setEditedElement    = function (editedElement){this.editedElement = editedElement; };
  425.     
  426.     method.release = function (){
  427.       this.super_release();
  428.       
  429.       if (this.editedElement && typeof(this.editedElement.release) == 'function')    
  430.         this.editedElement.release();
  431.       this.editedElement = null;
  432.     }
  433.   }
  434.   
  435.   HTML.__proto__.EditorWindow  = NOF_EditorWindow;
  436.     
  437.   /**
  438.     NOF.HTML.TabbedMenuEditorWindow class. Base class for editor windows.
  439.     
  440.     Constructor 
  441.     
  442.     @param _editedElem Object
  443.     @param _doc
  444.     @param _name
  445.   */
  446.   function NOF_TabbedMenuEditorWindow(_editedElement, _doc, _name){
  447.     this.__proto__  = NOF_TabbedMenuEditorWindow.prototype;  
  448.     
  449.     if (arguments.length == 0){ //default constructor call  
  450.       this.SUPER();    
  451.     }else{
  452.       this.SUPER( _doc, _name );  
  453.       this.editedElement = _editedElement;
  454.     }
  455.   }
  456.     
  457.   NOF_TabbedMenuEditorWindow.inherits( HTML.TabbedMenuWindow )
  458.   {
  459.     var member = NOF_TabbedMenuEditorWindow.prototype;  
  460.     member.editedElement = null;    
  461.   
  462.     var method = NOF_TabbedMenuEditorWindow.prototype;  
  463.     
  464.     method.parent_release = method.release;
  465.     method.release = function (){
  466.       this.parent_release();
  467.       if (this.editedElement && typeof(this.editedElement.release) == 'function')    
  468.         this.editedElement.release();
  469.       this.editedElement = null;
  470.     }
  471.     
  472.     method.getEditedElement    = function (){ return this.editedElement; };
  473.     method.setEditedElement    = function (editedElement){this.editedElement = editedElement; };
  474.   }
  475.   
  476.     HTML.__proto__.TabbedMenuEditorWindow  = NOF_TabbedMenuEditorWindow;
  477. }